define( 
    
    [ 'three', 'windowResize', 'detector', 'colladaLoader' ],
    
    function( THREE, THREEx, Detector, undefined ) {

        var scene = function( p ) {
 
            this.clock = new THREE.Clock();
            this.scene = new THREE.Scene();
            this.viewAngle = p.viewAngle;
            this.aspect = p.width / p.height;
            this.near = p.near;
            this.far = p.far;

            this.renderCalls = [ ];
            this.updateFunctions = [ ];

            this.camera =
                    new THREE.PerspectiveCamera( this.viewAngle,
                                                 this.aspect,
                                                 this.near,
                                                 this.far );

            this.scene.add( this.camera );

            if( p.camera.position ) { this.camera.position.set( p.camera.position.x, p.camera.position.y, p.camera.position.z ); }

            this.renderer = ( Detector.webgl )
                ? new THREE.WebGLRenderer( { antialias: true } )
                : new THREE.CanvasRenderer()

            this.renderer.setSize( p.width, p.height );
                        
            THREEx.WindowResize( this.renderer, this.camera );

            p.el.append( this.renderer.domElement );

            return this;
        }

        scene.prototype = {

            addToScene: function( p ) {

                this.scene.add( p.obj );

                if( p.lookAt ) {

                    this.camera.lookAt( p.obj.position );
                    this.camera.updateProjectionMatrix();
                }

                if( p.render ) { this.renderCalls.push( { obj: p.obj, fun: p.render } ); }

                return this;
        
            },

            animate: function() {

                requestAnimationFrame( $.proxy( this.animate, this ) );

                this.render();       

                this.update();

                return this;
            },

            render: function() {

                this.time = ( Date.now() - this.clock.startTime ) / 1000;

                for( var i = 0, ii = this.renderCalls.length; i < ii; i++ ) {

                    this.renderCalls[i].fun.apply( this, [ this.renderCalls[i].obj ] );
                }
                                
                this.renderer.render( this.scene, this.camera );
            },

            update: function() {
            }

        };

        return scene;

} );
   
